import {
  Component, OnInit, ViewEncapsulation, Input, Output,
  EventEmitter
} from '@angular/core';
import {imageUtil} from "@core/globals/globals.service";
import {FormGroup} from "@angular/forms";
import {ToolsService} from "@shared/service/tools/tools.service";

@Component({
  selector: 'seed-crowd-sku',
  templateUrl: './crowd-sku.component.html',
  styleUrls: ['./crowd-sku.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class CrowdSkuComponent implements OnInit {
  public imageUtil = imageUtil.path;
  public sponsorType = '请选择运动类型';
  public limitFocus = false;
  @Input() skuNumber: any;
  @Input() form: FormGroup;
  @Output() event = new EventEmitter();
  public rightList = {
    "buyTimesLimit": '',
    "price": '',
    "quantity": '',
    "rightDesc": "",
    "rightName": "",
    "sponsorType": ''
  };

  constructor(public toolsServices: ToolsService) {

  }

  ngOnInit() {

  }

  /**
   * @description 赞助形式
   * @author baoww765
   * @date 2017-11-12
   */
  selectSponsorType(event) {
    this.rightList.sponsorType = event;
  }

  /**
   * @description 删除sku
   * @author baoww765
   * @date 2017-11-14
   * @param index 被删除权益对应index
   */
  deleteSku(index) {
    const that = this;
    this.toolsServices.presentConfirm('确定删除该权益？', 1, function () {
      that.event.emit(index);
    });
  }

  focusLimit() {
    this.limitFocus = !this.limitFocus;
  }

  blurLimit() {
    this.limitFocus = !this.limitFocus;
  }
}
